<div class="filter">
    <div class="f1 item">
        <select data-am-selected>
        </select>
    </div>
    <div class="f2 item" style="margin-left: 20px;">
        <input type="text" value="今天" class="am-form-field" placeholder="" data-am-datepicker readonly />
    </div>
    <div class="clear"></div>
</div>
<a href="#" class="office">点击查看官方网址</a>
<table class="mobile">
    <thead>
    <tr>
        <th class="l">期数</th>
        <th>开奖号码</th>
    </tr>
    </thead>
    <tbody>
    </tbody>
</table>
<style type="text/css">
a.office {
    color: #000;
    line-height: 40px;
    text-decoration: underline;
    display: block;
    text-align: center;
}
</style>

<div class="list"></div>
<script>
    // 填充游戏
    var s = $(".f1 select");
    s.empty();
    var games = get_game_list();
    for (var i in games) {
        var g = games[i];
        s.append("<option value='" + g + "'>" + get_game_display_name(g) + "</option>");
    }
    s.val(game);
    s.trigger('changed.selected.amui');

    // 刷新结果
    var gameRule = Util.getGameRule(game);
    function refreshResult() {
        var g = s.val();
        gameRule = Util.getGameRule(g);
        var arr = $(".am-form-field").val().split("-");
        if ($(".am-form-field").val() == '今天') {
            var start = null;
            var end = null;
        }
        else {
            var t = new Date(parseInt(arr[0]), parseInt(arr[1]) - 1, parseInt(arr[2]));
            var start = t.getTime(), end = start + 24 * 3600 * 1000;
        }
        
        var data = {
            pageNum: 1,
            pageSize: 200,
            type: g,
        }
        if (start) data.start = start;
        if (end) data.end = end;
        CMD.lottery_query(data, function(r) {
            drawList(r.list);
        });
        if ($(".f1 select").val().startsWith("zy")) $("a.office").hide();
        else $("a.office").show();
    }

    // 绘制结果
    function drawList(list) {
        var table = $(".mobile tbody");
        table.empty();
        for (var i in list) {
            var o = list[i];
            if (!o.time) continue;
            var tr = $("<tr></tr>");
            tr.append('<td><div class="issue">' + o.issue + '期</div><div class="time">' + o.time.substring(5) + '</div></td>');
            
            // n个号码
            var c = "";
            for (var j = 0; j < o.red.length; j++) {
                var line = '<div class="car car__i__">__v__</div>';
                line = line.replace(/__i__/, parseInt(o.red[j]));
                if (window.customDrawNumber)
                    line = line.replace(/__v__/, customDrawNumber(o.red[j]));    
                else
                    line = line.replace(/__v__/, o.red[j]);
                c += line;
            }
            c += "<div class='clear'></div>";

            // 长龙
            var c2 = drawLong(o.red);

            tr.append("<td><div class='number1'>" + c + "</div><div class='number2'>" + c2 + "<div class='clear'></div></div></td>");
            table.append(tr);
        }
    }

    switch_page("result/result_" + game, $(".list"), function() {
        refreshResult();
    });
    $(".f1 select").change(function() {
        window.customDrawNumber = null;
        switch_page("result/result_" + $(".f1 select").val(), $(".list"), function() {
            refreshResult();
        });
    });
    $(".f2 input").change(refreshResult);

    $("a.office").click(function() {
        var url = '';
        switch ($(".f1 select").val()) {
            case "cqkl10": url = "http://www.cqcp.net/game/xync/"; break;
            case "gdkl10": url = "http://www.gdfc.org.cn/play_list_game_9.html"; break;
            case "cqssc": url = "http://www.cqcp.net/game/ssc/"; break;
            case "tjssc": url = "http://www.tjflcpw.com/news/ComputerCP.aspx?playType=4"; break;
            case "xjssc": url = "http://www.xjflcp.com/game/sscIndex"; break;
            case "jsk3": url = "http://caipiao.163.com/award/jskuai3/"; break;
            case "gd115": url = "http://gd11x5kjjg.icaile.com/"; break;
            case "lhc": url = "http://90kj.com/"; break;
            case "bjkl8": url = "http://www.bwlc.net/bulletin/keno.html"; break;
            case "bjpk10": url = "http://www.bwlc.net/bulletin/trax.html"; break;
        }
        window.location.href = url;
    });
</script>
